package weixinkeji.dev.dc.buy.order.h.manager;

import MyUI.ligerUI.bean.LigerUIOrderBy;
import MyUI.ligerUI.bean.LigerUIPage;
import MyUI.ligerUI.service.LigeruiService;
import java.time.LocalDate;
import sys.wx.ann.hm.M;
import sys.wx.c.ATR;
import sys.wx.c.components.cv.CV;
import sys.wx.m.db.SQL.mysql.common.orderby.OrderBy;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.SQL.mysql.common.where.WhereConfig;
import sys.wx.m.db.dao.mysql.Dao;
import sys.wx.util.ToolService;
import weixinkeji.dev.dc.buy.order.bean.FWYOrder;
import weixinkeji.dev.dc.buy.order.h.manager.vo.ManagerFWYRoprtVo;
import weixinkeji.dev.dc.buy.order.h.manager.vo.check.ManagerFWYReportCheck;

@sys.wx.ann.hm.H("view/buy/order/manager/fwy/r")

//身份类型授权。无需人工付权。
//代表 是服务员才能进行访问。
//@SQ(DCPower.ID_FWY)
public class ManagerFWYOrderReport {

    public static final String ORDERBY = OrderBy.getOrderBy("order_id", "DESC");

    //报表
    @M("/reportFWY")//通过 view/buy/order/manager/fwy/r/reportFWY.imy 访问
    public static String reportFWY(ATR a) {
        String index = CV.getParameter(a.request, "index", "(0|1|2){1}");
        LigerUIPage ob = LigeruiService.getPage(a.request);
        Where x = new Where(new WhereConfig(""));
        String mytj;
        switch (null == index ? 0 : Integer.parseInt(index)) {
            case 0: { //当日
                x.put(Where.TJ_IGNORE_NOTHING, "", "order_time", "LIKE", LocalDate.now() + "%");
                mytj = x.getWhere();
                a.printOne(LigeruiService.getGRID_1_2(
                        Dao.selectVastOrderBy(FWYOrder.class, mytj, ob.page, ob.pagesize, null == ob.sortname ? ORDERBY : OrderBy.getOrderBy(ob.sortname, ob.sortorder)),
                        Dao.selectCount(FWYOrder.class, mytj),
                        1)
                );
                return null;
            }
            case 1: {//指定订单
                String code = CV.getParameter(a.request, "code", "[0-9]{1,12}");
                if (null == code) {
                    return null;
                }
                x.put(Where.TJ_IGNORE_NOTHING, "", "order_code", "LIKE", "%" + code);
                mytj = x.getWhere();
                a.printOne(LigeruiService.getGRID_1_2(
                        Dao.selectVastOrderBy(FWYOrder.class, mytj, ob.page, ob.pagesize, null == ob.sortname ? ORDERBY : OrderBy.getOrderBy(ob.sortname, ob.sortorder)),
                        Dao.selectCount(FWYOrder.class, mytj),
                        1));
                return null;
            }
            case 2: {//按条件
                ManagerFWYRoprtVo rvo = CV.getObjectByFields(ManagerFWYRoprtVo.class, a.request, ManagerFWYReportCheck.doReportCheck());
                if (null == rvo) {
                    return null;
                }
                rvo.sort = rvo.sort.equals("3") ? null : rvo.sort;
                x.put(Where.TJ_IGNORE_NULL, "", "order_sort", "=", rvo.sort);
                x.put(Where.TJ_IGNORE_EMPTY_NULL, Where.AND, "room_code", "=", rvo.room);
                x.put(Where.putBetween(null, "", Where.AND, "order_time", rvo.date1, ToolService.IsNullOREmpty(rvo.date2) ? "" : rvo.date2 + " 23:59:59"));

                mytj = x.getWhereAotuRemove0ANDOR();
                a.printOne(LigeruiService.getGRID_1_2(
                        Dao.selectVastOrderBy(FWYOrder.class, mytj, ob.page, ob.pagesize, null == ob.sortname ? ORDERBY : OrderBy.getOrderBy(ob.sortname, ob.sortorder)),
                        Dao.selectCount(FWYOrder.class, mytj),
                        1));
                return null;
            }
        }
        return null;
    }

}
